/**
 * 
 */
package com.unlp.javaclickers.docente.modelo.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.google.common.collect.Lists;
import com.googlecode.genericdao.dao.hibernate.GenericDAOImpl;
import com.googlecode.genericdao.search.Search;
import com.unlp.javaclickers.docente.modelo.dao.ClaseDAO;
import com.unlp.javaclickers.helper.HibernateUtil;
import com.unlp.javaclickers.modelo.Clase;
import com.unlp.javaclickers.modelo.Docente;

/**
 * @author Pablo
 * 
 */
public class ClaseDAOImpl extends GenericDAOImpl<Clase, Integer> implements
		ClaseDAO {

	public ClaseDAOImpl() {
		super();
		this.setSessionFactory(HibernateUtil.getSessionFactory());
	}

	public ClaseDAOImpl(SessionFactory sessionFactory) {
		super();
		this.setSessionFactory(sessionFactory);
	}

	@Override
	public List<Clase> getClasesByDocente(Docente d) {
		Transaction transaction = HibernateUtil.getSessionFactory()
				.getCurrentSession().beginTransaction();
		Search params = new Search();
		List<Clase> result = Lists.newArrayList();
		params.addFilterEqual("docente", d);
		result = this.search(params);
		transaction.commit();
		return result;
	}

}
